﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using SevenShine;
using UnityEngine.SceneManagement;

public class Level4BeginEnd : MonoBehaviour {

    public Text text;
    //public AudioClip TypeWritingClip;
    public AudioClip Pass;
    public AudioClip DialogClip;

    private int s=3;
    private AudioSource audios;

    public static Level4BeginEnd Instance;

	// Use this for initialization
	void Start ()
    {
        Instance = this;
        audios = Camera.main.GetComponent<AudioSource>();

        //text.text = "";
        //audios.clip = TypeWritingClip;
        //audios.Play();
        //audios.loop = false;

        //text.DOText(LanguageMgr.GetInstance().ShowText("Level4_Dialog1"),2).SetEase(Ease.Linear);
        text.text = LanguageMgr.GetInstance().ShowText("Level4_Dialog1");

    }
	
	public void End()
    {
        StartCoroutine("GameEnd");
    }

    IEnumerator GameEnd()
    {
        yield return new WaitForSeconds(1);
        GameObject obj = Instantiate(Resources.Load("Prefabs/UI/DialogImage"),transform) as GameObject;

        audios.clip = DialogClip;
        audios.Play();
        audios.loop = false;
        float length = DialogClip.length;

        Text text = obj.GetComponentInChildren<Text>();
        text.DOText(LanguageMgr.GetInstance().ShowText("Level4_Dialog2"),length).SetEase(Ease.Linear).OnComplete(()=> 
        {
            //过关音效
            audios.clip = Pass;
            audios.Play();
        });

        yield return new WaitForSeconds(5);
        SceneManager.LoadScene("005");
    }
}
